package com.lsa.letcode.the104.maxDepthBt;

import static org.junit.Assert.assertEquals;

import java.io.InputStream;

import org.junit.Test;

import com.lsa.iview.trees.BinaryTree;
import com.lsa.iview.trees.BinaryTreeUtils;
import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.TreeNode;
import com.lsa.letcode.common.TreeUtils;
import com.lsa.letcode.common.TreeUtilsTest;
import com.lsa.letcode.the102.bstLevelOrderTrav.BstLevelOrderTravTest;

public class MaxDepthBtTest extends LetCodeTestBase {
	@Test
	public void test() throws Exception {
		test(TreeUtilsTest.class, "treeUtilsTest2.tgf", 6);
		test(TreeUtilsTest.class, "treeUtilsTest.tgf", 29);
		test(BstLevelOrderTravTest.class, "tree1.tgf", 4);
		test(this.getClass(), "oneNode.tgf", 1);
		test(this.getClass(), "test1.tgf", 10);
	}

	private void test(Class<?> c, String resName, int expected) {
		InputStream in = c.getResourceAsStream(resName);
		BinaryTree<Integer> t1 = BinaryTreeUtils.fromTgf(in);
//		System.out.println(BinaryTreeUtils.toString(t1.getRoot()));
		TreeNode n = TreeUtils.copyAdaptTree(t1.getRoot());
		Solution s = new Solution();
		assertEquals(expected, s.maxDepth(n));
	}
}
